home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_08 / phil6.c < prev    next >
Text File  |  1991-06-19  |  10KB  |  362 lines

  1.  
  2. Listing 6 - Changes to the function print_graphics_image (file
  3. djet.c)
  4.  
  5.  
  6.  
  7.  
  8.  
  9. print_graphics_image(image1, image2, image_name,
  10.                      il, ie, ll, le, image_colors,
  11.                      invert, caption, show_hist,
  12.                      color_transform)
  13.    char  caption[], image_name[], color_transform[];
  14.    int   image_colors, invert,
  15.          il, ie, ll, le, show_hist;
  16.    short image1[ROWS][COLS], image2[ROWS][COLS];
  17. {
  18.    char c[80],
  19.         page[80];
  20.  
  21.    FILE *printer;
  22.  
  23.    int  i,
  24.         j;
  25.  
  26.    unsigned long histogram[256], final_hist[256];
  27.    printer = fopen("prn", "w");
  28.  
  29.  
  30.       /**********************************************
  31.       *
  32.       *   Print a few blank lines on the page.
  33.       *
  34.       ***********************************************/
  35.  
  36.    strcpy(page, "                             ");
  37.    my_fwriteln(printer, page);
  38.    my_fwriteln(printer, page);
  39.  
  40.  
  41.       /*****************************************************
  42.       *
  43.       *   Read in two image arrays.
  44.       *
  45.       ******************************************************/
  46.  
  47.    printf("\nReading image");
  48.    read_tiff_image(image_name, image1, il, ie, ll, le);
  49.  
  50.  
  51.    printf("\nReading image");
  52.    read_tiff_image(image_name, image2, il, ie+100, ll, le+100);
  53.  
  54.       /*****************************************************
  55.       *
  56.       *   If show_hist is 1 OR do hist equalization
  57.       *   then zero the histogram and
  58.       *   calculate it for the two image arrays.
  59.       *
  60.       ******************************************************/
  61.  
  62.    if( (show_hist == 1)  ||
  63.        (color_transform[0] == 'H')){
  64.       zero_histogram(histogram);
  65.       zero_histogram(final_hist);
  66.       printf("\nDJET> Calculating histograms");
  67.       calculate_histogram(image1, histogram);
  68.       calculate_histogram(image2, histogram);
  69.    }
  70.  
  71.         /**************************************************
  72.         *
  73.         *   Alter the images to 64 gray shades.
  74.         *   Either do it with straight multiply
  75.         *   and divide or use hist equalization.
  76.         *
  77.         *   If using hist equalization then you must
  78.         *   also read and calculate the hist for
  79.         *   the other two image arrays that will be
  80.         *   printed.
  81.         *
  82.         ***************************************************/
  83.  
  84.    if(color_transform[0] == 'S'){
  85.    if(image_colors == 256){
  86.       for(i=0; i<ROWS; i++){
  87.          for(j=0; j<COLS; j++){
  88.             image1[i][j] = image1[i][j]/4;
  89.             image2[i][j] = image2[i][j]/4;
  90.         }
  91.       }
  92.    }  /* ends if image_colors == 256 */
  93.  
  94.  
  95.    if(image_colors == 16){
  96.       for(i=0; i<ROWS; i++){
  97.          for(j=0; j<COLS; j++){
  98.             image1[i][j] = image1[i][j]*4;
  99.             image2[i][j] = image2[i][j]*4;
  100.         }
  101.       }
  102.    }  /* ends if image_colors == 16 */
  103.    }  /* ends if color_transform == S */
  104.  
  105.    if(color_transform[0] == 'H'){
  106.       printf("\nReading image");
  107.       read_tiff_image(image_name, image1, il+100, ie, ll+100, le);
  108.       printf("\nReading image");
  109.       read_tiff_image(image_name, image2,
  110.                    il+100, ie+100, ll+100, le+100);
  111.       printf("\nDJET> Calculating histograms");
  112.       calculate_histogram(image1, histogram);
  113.       calculate_histogram(image2, histogram);
  114.  
  115.       printf("\nReading image");
  116.       read_tiff_image(image_name, image1, il, ie, ll, le);
  117.  
  118.       printf("\nReading image");
  119.       read_tiff_image(image_name, image2, il, ie+100, ll, le+100);
  120.  
  121.       printf("\nDJET> Equalizing histogram");
  122.       perform_histogram_equalization(image1, histogram,
  123.                                      64.0, 40000.0);
  124.       printf("\nDJET> Equalizing histogram");
  125.       perform_histogram_equalization(image2, histogram,
  126.                                      64.0, 40000.0);
  127.  
  128.       printf("\nDJET> Calculating histograms");
  129.       calculate_histogram(image1, final_hist);
  130.       calculate_histogram(image2, final_hist);
  131.  
  132.  
  133.    }  /* ends if color_transform == H */
  134.  
  135.  
  136.  
  137.       /************************************************
  138.       *
  139.       *   If invert is set them invert the transformed
  140.       *   image arrays (they now only have 64 shades
  141.       *   of gray).
  142.       *
  143.       *************************************************/
  144.  
  145.    if(invert == 1){
  146.       for(i=0; i<ROWS; i++){
  147.          for(j=0; j<COLS; j++){
  148.                image1[i][j] = 63 - image1[i][j];
  149.                image2[i][j] = 63 - image2[i][j];
  150.          }
  151.       }
  152.    }
  153.  
  154.  
  155.  
  156.         /**************************************************
  157.         *
  158.         *   Now set the graphics mode on the printer
  159.         *
  160.         ***************************************************/
  161.  
  162.    printf("\nBegin");
  163.    end_graphics_mode(printer);
  164.    select_300_dpi_resolution(printer);
  165.    set_raster_width(printer);
  166.    start_raster_graphics(printer);
  167.    select_full_graphics_mode(printer);
  168.  
  169.         /**************************************************
  170.         *
  171.         *   Print the two arrays to make a 100x200 output.
  172.         *   To do this you loop over 100 rows, set the 
  173.         *   r buffer to the image values, set the
  174.         *   graphics, and print the row via function
  175.         *   print_original_200_row.
  176.         *
  177.         ***************************************************/
  178.  
  179.    for(i=0; i<100; i++){
  180.       for(j=0; j<100; j++){
  181.          r[j]     = image1[i][j];
  182.          r[j+100] = image2[i][j];
  183.       }  /* ends loop over j */
  184.  
  185.       end_graphics_mode(printer);
  186.       select_300_dpi_resolution(printer);
  187.       set_raster_width(printer);
  188.       start_raster_graphics(printer);
  189.       select_full_graphics_mode(printer);
  190.  
  191.       print_original_200_row(printer, r);
  192.  
  193.       printf("\n\tPrinting row %d", i);
  194.    }  /* ends loop over i */
  195.  
  196.            /* ends first half */
  197.  
  198.  
  199.  
  200.       /*****************************************************
  201.       *
  202.       *   In order to print 200x200 repeat
  203.       *   the above steps for 2 more 100x100 arrays
  204.       *
  205.       ******************************************************/
  206.  
  207.  
  208.    printf("\nReading image");
  209.    read_tiff_image(image_name, image1, il+100, ie, ll+100, le);
  210.    printf("\nReading image");
  211.    read_tiff_image(image_name, image2,
  212.                    il+100, ie+100, ll+100, le+100);
  213.  
  214.  
  215.         /**************************************************
  216.         *
  217.         *   Alter the images to 64 shades of gray.
  218.         *
  219.         *   Either do it with straight multiply
  220.         *   and divide or use hist equalization.
  221.         *
  222.         ***************************************************/
  223.  
  224.  
  225.    if(color_transform[0] == 'S'){
  226.    if(image_colors == 256){
  227.       for(i=0; i<ROWS; i++){
  228.          for(j=0; j<COLS; j++){
  229.             image1[i][j] = image1[i][j]/4;
  230.             image2[i][j] = image2[i][j]/4;
  231.         }
  232.       }
  233.    }  /* ends if image_colors == 256 */
  234.  
  235.  
  236.    if(image_colors == 16){
  237.       for(i=0; i<ROWS; i++){
  238.          for(j=0; j<COLS; j++){
  239.             image1[i][j] = image1[i][j]*4;
  240.             image2[i][j] = image2[i][j]*4;
  241.         }
  242.       }
  243.    }  /* ends if image_colors == 16 */
  244.    }  /* ends if color_transform == S */
  245.  
  246.  
  247.  
  248.    if(color_transform[0] == 'H'){
  249.  
  250.       printf("\nDJET> Equalizing histogram");
  251.       perform_histogram_equalization(image1, histogram,
  252.                                      64.0, 40000.0);
  253.       printf("\nDJET> Equalizing histogram");
  254.       perform_histogram_equalization(image2, histogram,
  255.                                      64.0, 40000.0);
  256.  
  257.       printf("\nDJET> Calculating histograms");
  258.       calculate_histogram(image1, final_hist);
  259.       calculate_histogram(image2, final_hist);
  260.  
  261.    }  /* ends if color_transform == S */
  262.  
  263.  
  264.  
  265.       /************************************************
  266.       *
  267.       *   If invert is set them invert the transformed
  268.       *   image arrays (they now only have 64 shades
  269.       *   of gray).
  270.       *
  271.       *************************************************/
  272.  
  273.    if(invert == 1){
  274.       for(i=0; i<ROWS; i++){
  275.          for(j=0; j<COLS; j++){
  276.                image1[i][j] = 63 - image1[i][j];
  277.                image2[i][j] = 63 - image2[i][